package com.gmtx.syb.home.presenter;

import android.content.Context;

import com.gmtx.syb.bean.HomePagePropBean;
import com.gmtx.syb.bean.IndexAdBean;
import com.gmtx.syb.home.view.IHomeView;
import com.gmtx.syb.request.RequestUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2016/11/18.
 */

public class HomePresenter implements IHomePresenter {
    private IHomeView homeView;
    private Context context;

    public HomePresenter(Context context) {
        this.context = context;
    }

    public void attach(IHomeView homeView){
        this.homeView = homeView;
    }

    public void detach(){
        homeView = null;
    }

    @Override
    public void getHomePropData() {
        Map<String,String> args = new HashMap<>();
        RequestUtil.getInstance(context).doRequest(HomePagePropBean.class, args, new RequestUtil.RequestCallback<HomePagePropBean>() {
            @Override
            public void onRequestSucceed(HomePagePropBean data) {
                if (homeView != null) {
                    homeView.showHomePropData(data);
                }
            }

            @Override
            public void onRequestFailed(Throwable t) {
                if (homeView != null) {
                    homeView.getDataFailed(t);
                }
            }
        });
    }

    @Override
    public void getIndexAdData() {
        Map<String,String> args = new HashMap<>();
        RequestUtil.getInstance(context).doRequest(IndexAdBean.class, args, new RequestUtil.RequestCallback<IndexAdBean>() {
            @Override
            public void onRequestSucceed(IndexAdBean data) {
                if (homeView != null) {
                    homeView.showIndexAdData(data.getResult());
                }
            }

            @Override
            public void onRequestFailed(Throwable t) {
                if (homeView != null) {
                    homeView.getDataFailed(t);
                }
            }
        });
    }

    @Override
    public void getDailyData(int page) {

    }
}
